$(function () {
    var type = localStorage.getItem("type");
    $("#submitBtn").addClass("disable");
    if(type == 1){
        $("#bankTel").val(localStorage.getItem("ub_phone"));
    }else{
        $("#bankTel").val(localStorage.getItem("bankTel"));
    }

    /*发送验证码*/
    $("#send_code").click(function(){
        send_code();
    });

});

/*验证码*/
var wait = 60;
function countdown(obj, msg) {
    obj = $(obj);
    if (wait <= 0) {
        obj.removeClass("disabled");
        obj.prop("disabled", false);
        obj.html(msg);
        wait = 60;
    } else {
        if (msg == undefined || msg == null) {
            msg = obj.html();
        }
        obj.addClass("disabled");
        obj.prop("disabled", true);
        obj.html(wait + "秒后重新获取");
        wait--;
        setTimeout(function() {
            countdown(obj, msg)
        }, 1000)
    }
}
    
var b_id = localStorage.getItem("b_id"); /*订单ID*/
var user_bank_id = localStorage.getItem("user_bank_id");/*银行卡id*/
/*提交信息获取验证码----绑卡*/
function send_code() {
    
    var datas = {
        interface:'Secoo@consumerTransaction', 
        b_id:b_id,/*订单id*/
        user_bank_id:user_bank_id,/*绑定的银行卡id*/
    };

    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                countdown("#send_code","获取验证码");
                $("#submitBtn").removeClass("disable");
                /*提交*/
                $("#submitBtn").click(function(){
                    btn_Submit();
                });
                //falert(data.msg);
                if(type == 2){
                    applyId = data.result.applyId;
                    u_bank_id = data.result.ub_id;
                }
                //window.location.href="";
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}

/*提交---立即支付---信用卡支付消费验证接口：Secoo@consumerTransactionVerification*/
function btn_Submit() {
    var phone_code = $("#code").val();/*验证码*/
    if(phone_code == ""){
        falert("请输入验证码");
        return false;
    }
    var datas = {
        interface:'Secoo@consumerTransactionVerification', 
        b_id: b_id,/*订单id*/
        user_bank_id:user_bank_id,/*信用卡ID*/
        phone_code:phone_code,/*验证码*/
    };
    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                localStorage.removeItem("b_period");
                localStorage.removeItem("p_name");
                localStorage.removeItem("type");
                localStorage.removeItem("ub_phone");
                localStorage.removeItem("user_bank_id");
                window.location.href="/secoo/pay_success";
            } else if (data.status == '5000') {
                falert(data.msg);
            }
        }
    });
}